<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const addAll = function() {
            console.log('重新计算')
            let result = 0;
            console.log('arguments',arguments)
            for (let i =0; i<arguments.length; i++) {
                result += arguments[i];
            }
            return result;
        }
        // 使用缓存代理
        const proxyAddAll = (function(){
            // 求和结果缓存
            let resultCache = {};
            return function() {
                // 保存参数key
                let arg = Array.prototype.join.call(arguments, ',');
                if (arg in resultCache) {
                    return resultCache[arg]
                }
                return resultCache[arg] = addAll(...arguments)
            }
        })();
        console.log('33',proxyAddAll(1,2,3,4))
        console.log('44',proxyAddAll(1,2,3,4))
        function func1() {
  console.log(arguments[0]);
  // expected output: 1

  console.log(arguments[1]);
  // expected output: 2

  console.log(arguments[2]);
  // expected output: 3
}

func1(1, 2, 3);
    </script>
</body>
</html>